package com.example.apple.ddhr_new.utils;

import android.text.TextUtils;

import org.apache.commons.lang3.StringUtils;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.Random;

public class StringUtil {
    public  static  String phoneString(String phone){
        if(null==phone){
            return phone;
        }else if(phone.length()>=11){
            return phone.substring(0,3)+"****"+phone.substring(phone.length()-4,phone.length());
        }else if(phone.length()<=7){
            return  phone;
        }else {

            return phone.substring(0,3)+"****"+phone.substring(phone.length()-4,phone.length());
        }

    }
    public static boolean isMobileNO(String mobileNums) {
        /**
         * 判断字符串是否符合手机号码格式
         * 移动号段: 134,135,136,137,138,139,147,150,151,152,157,158,159,170,178,182,183,184,187,188
         * 联通号段: 130,131,132,145,155,156,170,171,175,176,185,186
         * 电信号段: 133,149,153,170,173,177,180,181,189
         * @param str
         * @return 待检测的字符串
         */
        String telRegex = "^(1)\\d{10}$";// "[1]"代表第1位为数字1，"[358]"代表第二位可以为3、5、8中的一个，"\\d{9}"代表后面是可以是0～9的数字，有9位。
        if (TextUtils.isEmpty(mobileNums))
            return false;
        else
            return mobileNums.matches(telRegex);
    }
    public  static  String timeStringForMinute(int time){
       if(time<=0){
           return   time+"";
       }else
       {
           int hours = time/60;
           int minute = time%60;
           if(hours==0){
               if(minute==0)
                   return "";
               return minute+"分钟";
           }
           if(minute==0){
               return hours+"小时";
           }
           return hours+"小时"+minute+"分钟";

       }





    }

    public  static  String utfString(String str){


        if(StringUtils.isEmpty(str))
            return "";
        try {
            String strUTF8 = URLDecoder.decode(str, "UTF-8");
            return strUTF8;
        } catch (UnsupportedEncodingException e) {
            return str;
        }



    }
    public  static  String radom3String(){


        Date date = new Date();
        String dateStr = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(date);
        Random ra =new Random();
        dateStr =dateStr+ra.nextInt(10);
        dateStr =dateStr+ra.nextInt(10);
        dateStr =dateStr+ra.nextInt(10);
        return dateStr;


    }

    public static int getDayOfWeek() {
        Calendar cal = Calendar.getInstance();
        int i = cal.get(Calendar.DAY_OF_WEEK);
        int day = 0;
        switch (i) {
            case 1:
                day= 7;
                break;
            case 2:
                day=1;
                break;
            case 3:
                day=2;
                break;
            case 4:
                day=3;
                break;
            case 5:
                day=4;
                break;
            case 6:
                day=5;
                break;
            case 7:
                day=6;
                break;
            default:
                break;
        }

        return day;
    }

    public static int getMinute(ArrayList<String> date) {

        if(date==null||date.size()!=2){
            return 0;
        }

        return Integer.valueOf(date.get(0))*60+Integer.valueOf(date.get(1));


    }
}
